What is a 304?

304 Not Modified

The HTTP 304 Not Modified client redirection response code indicates that the server is telling the client that the resource at the requested URL hasn't changed since the last time the client downloaded it.

Here's a breakdown of key aspects:

  • Purpose: To reduce network bandwidth usage and improve website performance by allowing the client to reuse a previously cached version of the resource.

  • How it Works: The client sends a conditional request with an If-Modified-Since or If-None-Match header.

    • If-Modified-Since: This header specifies the date and time the client last received the resource. The server compares this date with the resource's last modified date.
    • If-None-Match: This header specifies the ETag (entity tag) value that the client previously received for the resource. The server compares this ETag with the current ETag of the resource.
  • Server Response: If the resource hasn't been modified since the date specified in If-Modified-Since, or if the ETag in If-None-Match matches the current ETag, the server responds with a 304 Not Modified status code. The server should not include a message body in the response.

  • Client Action: Upon receiving a 304 response, the client uses its cached version of the resource. The response effectively tells the client to refresh its cache entry with the information from the server's response headers (e.g., updated expiry time).

  • Important Headers:

    • Cache-Control: Controls how the resource should be cached by the client and intermediary caches.
    • ETag: A unique identifier for a specific version of a resource. Crucial for If-None-Match conditional requests.
    • Last-Modified: Indicates the last date and time the resource was modified. Used by If-Modified-Since.
    • Expires: Specifies the date/time after which the response is considered stale.
    • Date: The date and time at which the response was originated by the server.
  • Benefit: Significantly reduces the amount of data transferred between the server and the client. This leads to faster page load times and lower bandwidth costs, especially for resources that don't change frequently.

  • Common Use Cases: Caching static assets like images, CSS files, and JavaScript files.

  • Requirements: The server must correctly implement conditional GET requests using If-Modified-Since and/or If-None-Match headers. It also needs to accurately manage ETag and Last-Modified values.